#include "Triangle.h"

ConcreteElementLoader<Triangle> *Triangle::loader = new ConcreteElementLoader<Triangle>();

Triangle::Triangle(TiXmlElement *elem) { // TODO IMPLEMENT EXCEPTIONS
	if( elem != NULL ) {
		if( elem->QueryFloatAttribute("x1", &(point1.x)) == TIXML_SUCCESS &&
			elem->QueryFloatAttribute("y1", &(point1.y)) == TIXML_SUCCESS &&
			elem->QueryFloatAttribute("z1", &(point1.z)) == TIXML_SUCCESS &&
			elem->QueryFloatAttribute("x2", &(point2.x)) == TIXML_SUCCESS &&
			elem->QueryFloatAttribute("y2", &(point2.y)) == TIXML_SUCCESS &&
			elem->QueryFloatAttribute("z2", &(point2.z)) == TIXML_SUCCESS &&
			elem->QueryFloatAttribute("x3", &(point3.x)) == TIXML_SUCCESS &&
			elem->QueryFloatAttribute("y3", &(point3.y)) == TIXML_SUCCESS &&
			elem->QueryFloatAttribute("z3", &(point3.z)) == TIXML_SUCCESS ) {
			#ifdef DEBUG
			printf("Triangle read: p1(%0.1f,%0.1f,%0.1f), p2(%0.1f,%0.1f,%0.1f), p3(%0.1f,%0.1f,%0.1f), \n", 
				point1.x, point1.y, point1.z, 
				point2.x, point2.y, point2.z,
				point3.x, point3.y, point3.z);
			#endif
		}
	}
}

void Triangle::displayElement() {
	glBegin(GL_TRIANGLES);
		glVertex3f(point1.x, point1.y, point1.z);
		glVertex3f(point2.x, point2.y, point2.z);
		glVertex3f(point3.x, point3.y, point3.z);
	glEnd();
}